package com.cs.controller;

import com.cs.domain.User;
import com.cs.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "会员管理的接口")
@RequestMapping("/p/user")
public class MemberController {
    @Autowired
    private UserService userService;
    /**
     * 更新用户的信息
     * @return
     */
    @PutMapping("/setUserInfo")
    public ResponseEntity<Void> setUserInfo(@RequestBody User user){
        //获得当前的用户
        String openId = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        user.setUserId(openId);
        userService.updateById(user);
        return ResponseEntity.ok().build();
    }
}
